package com.zhihaoliang.moshi

import com.zhihaoliang.moshi.biz.adapter.*
import com.zhihaoliang.moshi.biz.decode.base64Decode
import com.zhihaoliang.moshi.biz.io.OutputStreamJava
import com.zhihaoliang.moshi.biz.io.inputStream
import com.zhihaoliang.moshi.biz.io.outStream
import com.zhihaoliang.moshi.biz.models.plantData
import com.zhihaoliang.moshi.biz.parser.parserJsonClass
import com.zhihaoliang.moshi.biz.parser.parserJsonList
import com.zhihaoliang.moshi.biz.parser.parserKotlinData
import com.zhihaoliang.moshi.biz.parser.printPretty
import com.zhihaoliang.moshi.list.ListActivity
import com.zhihaoliang.moshi.list.ListItem
import kotlinx.coroutines.launch

class MainActivity : ListActivity() {
    override val listItem: List<ListItem> = listOf(
        ListItem("通过 JsonClass 解析 Kotlin", 0),
        ListItem("通过 KotlinJsonAdapterFactory 解析 Kotlin", 1),
        ListItem("newParameterizedType 解析 List", 2),
        ListItem("indent 格式化打印", 3),
        ListItem("InputSteam 流的解析", 4),
        ListItem("Kotlin OutputStream 的对象写入Json以及泛型解析", 5),
        ListItem("Java OutputStream 的对象写入Json以及泛型解析", 6),
        ListItem(""""CustomTypeAdapter 和 @Json(name = "hidden_card")""", 7),
        ListItem("Base64 转化", 8),
        ListItem("自定义 AdapterFactory", 9),
        ListItem("自定义代理 ", 10),
        ListItem("JsonQualifier 颜色转换", 11),
        ListItem("当不是正常值时，选择默认值", 12),
    )

    override fun onItemClick(item: ListItem) {
        when (item.index) {
            0 -> parserJsonClass()
            1 -> parserKotlinData()
            2 -> parserJsonList()
            3 -> printPretty()
            4 -> mainScope.launch {
                inputStream(applicationContext)
            }
            5 -> outStream(plantData, applicationContext)
            6 -> OutputStreamJava.outStream(plantData, applicationContext)
            7 -> parserCustom()
            8 -> base64Decode()
            9 -> customAdapterFactory()
            10 -> customAdapterWithDelegate()
            11 -> customQualifier()
            12 -> recoverFromTypeMismatch()
        }
    }
}